<?php
/**
 * Feature
 * 
 * @package BugZapp
 * @author Mark Johnson
 * @copyright 2010
 * @version 1.0
 * @access public
 */
class Feature extends DBObject
{
    var $fid = 0;
    
    var $description = 'Please enter a description.';
    var $details = 'Please enter details.';
    
    /**
     * Feature::Feature()
     * 
     * @return
     */
    public function Feature($data = NULL) 
    {
    	$this->table = 'feature';
        
        $this->id_name = 'fid';
        
        $this->fields = array(
            'description' => "'%s'",
            'details' => "'%s'"
        );
        
        parent::DBObject($data);
    }
    
    /**
     * Feature::schema()
     * 
     * @return
     */
    public static function schema()
    {
        return 'CREATE TABLE IF NOT EXISTS `feature` (
    			  `fid` int(10) unsigned NOT NULL AUTO_INCREMENT,
    			  `description` varchar(255) DEFAULT NULL,
    			  `details` text,
    			  PRIMARY KEY (`fid`),
    			  UNIQUE KEY `fid_UNIQUE` (`fid`)
    			) ENGINE=InnoDB DEFAULT CHARSET=utf8';
    }
    
    /**
     * Feature::install()
     * 
     * @return
     */
    public static function install()
    {
        db_query('DROP TABLE IF EXISTS feature');
    	$result = db_query(Feature::schema());
    	
    	if ($result !== FALSE)
    	{
    		db_query("INSERT INTO feature (description, details) VALUES ('Please enter a description.', 'Please enter details.')");
    		db_query("UPDATE feature SET fid=0 WHERE description='Please enter a description.'");
            db_query('ALTER TABLE feature AUTO_INCREMENT=1');
            
    		system_set_message('The <code>features</code> table was successfully created.');
    		
			return TRUE;
    	}
    	else
    	{
    		system_set_message('The <code>features</code> table was not created.');
    		
    		return FALSE;
    	}
    }
    
    /**
     * Feature::uninstall()
     * 
     * @return
     */
    public static function uninstall()
    {
        $result = db_query('DROP TABLE IF EXISTS feature');
    	if ($result !== FALSE)
    	{			
    		system_set_message('The <code>feature</code> table was successfully removed.');
    		
    		return TRUE;
    	}
    	else
    	{
    		system_set_message('The <code>feature</code> table was not removed.');
    		
    		return FALSE;
    	}
    }
}
